package org.example.service;

import org.example.annotation.Action;
import org.example.bean.Bean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Service
@Scope("prototype")
public class DemoAnnotationService {

    @PostConstruct
    public void init(){
        System.out.println("init");
    }
    @PreDestroy
    public void destory() {
        System.out.println("destory");
    }
    @Autowired
    private Bean bean;

    @Autowired
    private Environment environment;

    @Action(name = "注解拦截")
    public void add(){
        System.out.println(bean.getAnother());
        System.out.println(bean.getAuthor());
        System.out.println(bean.getPort());
        System.out.println(bean.getOsName());
        System.out.println(bean.getRandomNumber());
        System.out.println(bean.getTestUrl());
        System.out.println(environment.getProperty("book.author"));
        System.out.println(environment.getProperty("server.port"));
        System.out.println(environment.getActiveProfiles()[0]);
        System.out.println(environment.getDefaultProfiles()[0]);
    }

}
